#include "dominion.h"
#include <stdio.h>
#include <assert.h>
#include <time.h>
#include <stdlib.h>
#include <string.h>
// We are testing playCard()

int main() {
	printf("TESTING playCard():\n");
	// Setup control and experiment
	
	struct gameState *G = newGame();

	// Get entopy to pass to initialize game
	srand(time(NULL));
	int r = rand();

	int k[10] = {adventurer, gardens, embargo, village, minion, mine, cutpurse, sea_hag, tribute, smithy};

	initializeGame(2, k, r, G);
	
	// Make sure we only play when in correct phase
	printf("Testing for correct phase detection.\n");
	G->phase = 1;
	assert(playCard(0, 0, 0, 0, G) == -1);
	printf("Test Passed\n");

	// Make sure we only play when we have enough actions	
	printf("Testing for correct numActions error catching\n");
	G->phase = 0;	
	G->numActions = 0;
	assert(playCard(0, 0, 0, 0, G) == -1);
	printf("Test passed\n");

	// Make sure we only play when we aren't playing action card	
	printf("Testing for action card error catching\n");
	G->phase = 0;
	G->numActions = 1;
	G->hand[0][0] = curse;
	G->whoseTurn = 0;
	assert(playCard(0, 0, 0, 0, G) == -1);
	printf("Test Passed\n");

	// Setup for playing Smithy
	printf("Testing for correct playing of smithy as control\n");
	G->phase = 0;
	G->numActions = 1;
	G->hand[0][0] = smithy;
	G->whoseTurn = 0;
	int pre_hand_count = G->handCount[0];
	// Note: this test unfortunately depends on smithy being 	
	// correctly implemted
	assert(playCard(0, 0, 0, 0, G) == 0);
	assert(G->handCount[0] == pre_hand_count + 2);
	assert(G->numActions == 0);
	printf("Test Passed\n");
	printf("All tests passed.\n");

	return 0;
}
